package com.fzh.client;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientReadThread extends Thread {
    private Socket socket;

    public ClientReadThread(Socket socket){
        this.socket=socket;
    }
    @Override
    public void run(){
        try {
            InputStream is=socket.getInputStream();
            DataInputStream dis =new DataInputStream(is);
            while(true){
                try{
                    String msg= dis.readUTF();
                    System.out.println(msg);
                }catch (Exception e){//捕捉用户下线的异常。
                    System.out.println("用户下线了");
                    dis.close();
                    socket.close();
                    break;
                }

            }
        } catch (IOException e) {

            throw new RuntimeException(e);
        }
    }

}
